package com.py.credit.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.py.credit.common.logs.ExceptionLogger;
import com.py.credit.common.rest.RestServiceResult;
import com.py.credit.entity.SysUser;
import com.py.credit.service.XypjRemoteBaseService;
import com.py.credit.utils.UuidUtil;
import com.py.framework.core.helper.HttpServletHelper;

@RestController
@RequestMapping(value = "/common")
public class CommonController {

	private static final int ZERO = 0;

	private static final String ZERO_STR = "0";
	
	private final static String FRONT_TABLE_ID = "common";

	@Autowired
	private XypjRemoteBaseService xypjRemoteBaseService;

	
	@RequestMapping(value = "/getUuid.json")
	public RestServiceResult<String> getUuid(String indexCatModelId,String standard,
			HttpServletResponse response,HttpServletRequest request) {
		String token = HttpServletHelper.getUserToken(request);
		RestServiceResult<String> result = new RestServiceResult<String>();
		// 获取当前用户信息
		RestServiceResult<SysUser> user = xypjRemoteBaseService.getCurrentUser(token);
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("BatchLogController#getTableList", "未获取到当前用户信息！");
				return result;
			}
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;
		}
		try {
			String uuid=UuidUtil.getUUid();
			result.setData(uuid);
			return result;
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("共享日志导出异常，请稍后再试！");
			ExceptionLogger.error("共享日志导出异常！", e.getMessage(), e);
			return result;
		}
	}
	
	
}
